package com.hrt.day07.generic

/**
 * 泛型的上界
 */
case class AA(val age: Int) extends Ordered[AA]{
    override def compare(that: AA): Int = age - that.age
}
object Generic2 {
    def main(args: Array[String]): Unit = {
        val aa = compare(new AA(10), new AA(20))
        
        println(aa)
        
    }
    //定义泛型的上界:定义传入的是Ordered的子类
    def compare[T <: Ordered[T]](x: T, y: T):T = {
        if(x > y) x
        else y
    }
}